<template>
<div class="businForm-wrapper">
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             :rules="rules"
             label-width="120px">
          <el-form-item label="控制项编号：">
            <el-input v-model="inputForm.codes" :disabled="true"></el-input>
          </el-form-item>
          <el-form-item label="控制项名称：">
              <el-input v-model="inputForm.names" placeholder="" maxlength="20" :disabled="true"></el-input>
           </el-form-item>
      <el-form-item label="取值来源：" prop="valueSource" required>
        <el-select clearable v-model="inputForm.valueSource" :disabled="true" placeholder="请选择">
          <el-option
            v-for="item in valueSourceList"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="变量值："  prop="svalue" required>
        <el-input :disabled="inputForm.valueSource!=3" v-model="inputForm.svalue" ></el-input>
      </el-form-item>
<!--      <el-form-item label="调用方法名：">-->
<!--        <el-input v-model="inputForm.callMethod" placeholder=""></el-input>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="表达式：">-->
<!--        <el-input type="textarea" v-model="inputForm.expression" placeholder=""></el-input>-->
<!--      </el-form-item>-->
<!--      <el-form-item>-->
<!--          <el-checkbox v-model="inputForm.isDisplay" :true-label='1' :false-label='0'>租户端不显示</el-checkbox>-->
<!--      </el-form-item>-->
    </el-form>
    <span slot="footer" class="dialog-footer">
        <el-button type="primary" v-if="method != 'view'" @click="doSubmit('inputForm')" v-noMoreClick>确定</el-button>
      <el-button @click="visible = false">取消</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  import { updateModelBusinessValue } from '@/api/model/model.js'
  export default {
    data () {
      return {
        valueSourceList: [{
          value: 1,
          label: '全局'
        }, {
          value: 2,
          label: '流程'
        }, {
          value: 3,
          label: '模型'
        }, {
          value: 4,
          label: '业务'
        }, {
          value: 5,
          label: '其他'
        }],
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          codes: '',
          names: '',
          svalue: '',
          callMethod: '',
          expression: '',
          isDisplay: '',
          valueSource: ''
        },
        rules: {
          svalue: [{ required: true, message: '变量值不能为空', trigger: 'blur' }],
          valueSource: [{ required: true, message: '取值来源不能为空', trigger: 'blur' }]
        }
      }
    },
    methods: {
    	handleClose(done) {
			this.$Msg.confirm({
				title:'您确定要关闭吗？',
				content:this.GLOBAL.FORM_CLOSE_TIPS,
				confirmCall:()=>{
					done();
				}
			})
		},
      init (method, obj) {
        this.method = method
        this.inputForm.id = obj.id
        if (method === 'add') {
          this.title = `新增提示语`
        } else if (method === 'edit') {
          this.title = '控制项设置'
          this.visible = true
          this.loading = false
          this.$set(this.inputForm, 'codes', obj.codes)
          this.$set(this.inputForm, 'names', obj.names)
          this.$set(this.inputForm, 'valueSource', obj.valueSource)
          this.$set(this.inputForm, 'svalue', obj.svalue)
          this.$set(this.inputForm, 'callMethod', obj.callMethod)
          this.$set(this.inputForm, 'expression', obj.expression)
          this.$set(this.inputForm, 'isDisplay', obj.isDisplay)
        } else if (method === 'view') {
          this.title = '查看提示语'
        }
        this.visible = true
        this.loading = false
        // this.$nextTick(() => {
        //   this.$refs.inputForm.resetFields()
        //   if (method === 'edit' || method === 'view') { // 修改或者查看
        //     this.loading = true
        //     this.$http({
        //       url: `/model/busin/list?id=${this.inputForm.id}`,
        //       method: 'get'
        //     }).then(({data}) => {
        //       if (data.code === '200') {
        //
        //       }
        //       console.log(data)
        //       this.inputForm = this.recover(this.inputForm, data.result)
        //       this.loading = false
        //     })
        //   }
        // })
      },
      // 表单提交
      doSubmit (formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.loading = true
            updateModelBusinessValue(this.inputForm).then((res) => {
              if (res.data.code === '200') {
                this.$message({
                  message: '编辑成功',
                  type: 'success'
                })
                this.visible = false
              this.$emit('refreshDataList')
            } else {
                this.$message({
                  message: res.data.message,
                  type: 'error'
                })
              }
            })
            this.loading = false
          }
        })
      }
    }
  }
</script>
<style lang="scss" scoped>
.businForm-wrapper{
  ::v-deep.el-dialog{
    width: fit-content;
    .el-dialog__header{
      padding: 0 20px !important;
      height: 41px;
      line-height: 41px;
    }
    .el-dialog__headerbtn{
      top: 11px;
    }
    .el-dialog__title{
      font-size: 16px;
      color: #333333;
    }
    .el-dialog__body{
      .el-form-item{
        line-height: inherit;
        margin-bottom: 20px;
        .el-form-item__label,.el-form-item__content{
          line-height: 32px;
        }
        .el-input{
          height: 32px;
          input {
            height: 32px;
            width: 320px;
            border: 1px solid #AAAAAA;
            border-radius: 4px;
            color: #333333;
            padding: 0 10px !important;
          }

          input:hover, input:focus {
            border-color: #1890ff;
          }

          .el-input__inner::-webkit-input-placeholder {
            color: #999999;
          }
          .el-textarea__inner::-webkit-input-placeholder {
            color: #999999;
          }
          .el-input__inner::-webkit-input-placeholder {
            color: #999999;
          }
          .el-textarea__inner::-webkit-input-placeholder {
            color: #999999;
          }
        }
        .el-input.is-disabled{
          input:hover, input:focus {
            border-color: #AAAAAA;
          }
        }
        .el-textarea__inner{
          border: 1px solid #AAAAAA;
          border-radius: 4px;
          resize: none;
          height: 69px;
        }
        .el-input{
          .el-input__icon{
            line-height: 32px;
          }
        }
        .el-checkbox__inner{
          border: 1px solid #666666;
        }
        .el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner{
          border: 1px solid #1890FF;
        }
      }


    }
  }
}
</style>
